<div class="page-content">
    <div class="page-header">
        <h1>

            Form Pembelian SN
            <small>
                    <i class="icon-double-angle-right"></i>
                    Pembelian SN Agent
            </small>
        </h1>
    </div><!-- /.page-header -->

<?php
if ($this->msg != "") {
    ?>
    <div class="alert alert-info">
        <button type="button" class="close" data-dismiss="alert">
            <i class="icon-remove"></i>
        </button>

        <strong>
            <i class="icon-ok"></i>
        </strong>

        <?php echo $this->msg; ?>
        <br />
    </div>
    <?php
}
if ($this->errmsg) {
    ?>
    <div class="alert alert-danger">
        <button type="button" class="close" data-dismiss="alert">
            <i class="icon-remove"></i>
        </button>

        <strong>
            <i class="icon-remove"></i>

        </strong>

        <?php echo $this->errmsg; ?>
        <br />
    </div>
<?php
}

if ($this->msg == "") {

 ?>
    
    <div class="row">
        <div class="col-xs-12">
            <!-- PAGE CONTENT BEGINS -->

            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-main">
                        <div id="fuelux-wizard" class="row-fluid" data-target="#step-container">
                            <ul class="wizard-steps">
                                <li data-target="#step1" class="active">
                                    <span class="step">1</span>
                                    <span class="title">Input Jumlah Pembelian</span>
                                </li>

                                <li data-target="#step2">
                                    <span class="step">2</span>
                                    <span class="title">Metode Pembayaran</span>
                                </li>

                                <li data-target="#step3">
                                    <span class="step">3</span>
                                    <span class="title">Konfirmasi Pemesanan</span>
                                </li>
                            </ul>
                        </div>

                        <hr />

                        <form class="form-horizontal" id="inputForm" name="inputForm" method="post">
                            <div class="step-content row-fluid position-relative" id="step-container">
                                <div class="step-pane active" id="step1">
                                    <h3 class="lighter block green">Masukkan jumlah pembelian SN</h3>
                                    <br><br>
                                        <div class="form-group">
                                            <label for="qty" class="col-xs-12 col-sm-3 control-label no-padding-right">Harga Satu SN&nbsp;&nbsp; </label>
                                            <div class="controls">
                                                
                                                    <input type="text" class="col-xs-10 col-sm-1" value="<?php echo number_format($this->snPrice);?>" readonly />
                                                    <input type="hidden" id="price" name="price" value="<?php echo $this->snPrice;?>" />
                                                
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="qty" class="col-xs-12 col-sm-3 control-label no-padding-right">Jumlah SN&nbsp;&nbsp; </label>
                                            <div class="controls">
                                                
                                                    <input type="text" class="input-mini" id="qty" name="qty" value="10" />
                                                
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="qty" class="col-xs-12 col-sm-3 control-label no-padding-right">Total Harga&nbsp;&nbsp; </label>
                                            <div class="controls">
                                                
                                                    <input type="text" class="col-xs-10 col-sm-2" id="totalPriceShow" value="<?php echo number_format($this->snPrice);?>" readonly />
                                                    <input type="hidden" id="totalPrice" name="totalPrice" value="<?php echo $this->snPrice;?>" />
                                                
                                            </div>
                                        </div>
                                </div>

                                <div class="step-pane" id="step2">
                                    <div class="row-fluid">
                                        <h3 class="lighter block green">Pilih metode Pembayaran</h3>
                                        <br>
                                        <div class="form-group">
                                            <label for="inputWarning" class="col-xs-12 col-sm-3 control-label no-padding-right">&nbsp;&nbsp; </label>
                                            <div class="radio">
                                                <label>
                                                    <input name="rdPembayaran" type="radio" value="1" class="ace" onclick="pilihBayar(this.value)" required/>
                                                    <span class="lbl"> Cash</span>
                                                </label>
                                            </div>
                                            <label for="inputWarning" class="col-xs-12 col-sm-3 control-label no-padding-right">&nbsp;&nbsp; </label>
                                            <div class="radio">
                                                <label>
                                                    <input name="rdPembayaran" type="radio" id="rdTukarPoint" value="2" class="ace" onclick="pilihBayar(this.value)" required/>
                                                    <span class="lbl"> Tukar Point (Point Anda: <?php echo number_format($this->balance);?>)</span>
                                                </label>
                                            </div>
                                            <label for="inputWarning" class="col-xs-12 col-sm-3 control-label no-padding-right">&nbsp;&nbsp; </label>
                                            <div class="radio">
                                                <label>
                                                    <input name="rdPembayaran" type="radio" value="3" class="ace" onclick="pilihBayar(this.value)" required />
                                                    <span class="lbl"> Transfer</span>
                                                </label>
                                            </div>
                                            <label for="inputWarning" class="col-xs-12 col-sm-3 control-label no-padding-right">&nbsp;&nbsp; </label>
                                            
                                            <div id="divBank" class="radio" style="visibility:hidden;position:absolute">
                                                    <div id="accordion" class="accordion-style1 panel-group">
                                                        <div class="panel panel-default">
                                                                <div class="panel-heading">
                                                                        <h4 class="panel-title">
                                                                                <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                                                                                        <i class="icon-angle-down bigger-110" data-icon-hide="icon-angle-down" data-icon-show="icon-angle-right"></i>
                                                                                        &nbsp;Transfer ke salah satu rekening berikut:
                                                                                </a>
                                                                        </h4>
                                                                </div>

                                                                <div class="panel-collapse collapse in" id="collapseOne">
                                                                    <div class="panel-body" id="lbBank">
                                                                                * BCA Norek: 28-307-11-841, A/N CUCU SYAMSUL MILLAH, Cabang Ujungberung Bandung<br>
                                                                                * BRI Norek: 0750-01-025013-53-0, A/N CUCU SYAMSUL MILLAH, Cabang Cibiru Bandung<br>
                                                                                * BNI Norek: 002-453-1955, A/N CUCU SYAMSUL MILLAH, Cabang Majalengka<br>
                                                                                * MANDIRI Norek: 131-00-0726422-1, A/N CUCU SYAMSUL MILLAH, Cabang Ujungberung Bandung<br>

                                                                        </div>
                                                                </div>
                                                        </div>

                                                </div>



                                                    <?php
                                                    /*
                                                    while ($this->accountsPT->next()) {
                                                            $res = $this->accountsPT->current();
                                                            echo "* Bank ".$res["bank_name"]." No Rek: ".$res["bank_acc_no"].", A/N: ".$res["bank_acc_name"]."<br>";
                                                    }
                                                     *
                                                     */
                                                    ?>

                                                </div>
                                            <input type="hidden" id="caraBayar" name="caraBayar" required/>
                                        </div>

                                    </div>
                                </div>

                                <div class="step-pane" id="step3">
                                    <div class="row-fluid">
                                        <h3 class="lighter block green">Konfirmasi Pembelian</h3>
                                        <small>
                                                <i class="icon-double-angle-right"></i>
                                                Klik Finish jika pesanan sudah benar.
                                        </small>

                                        <br>
                                        <br>


                                        <div class="form-group">
                                            <label class="col-sm-2 control-label no-padding-right" for="code"> Jumlah Pembelian SN: </label>

                                            <div class="col-sm-9">
                                                <label for="inputWarning" id="lbKonfirmJumlah" class="col-xs-10"></label>
                                                
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label no-padding-right" for="code"> Total Harga: </label>

                                            <div class="col-sm-9">
                                                <label for="inputWarning" id="lbKonfirmTotal" class="col-xs-10"></label>

                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label no-padding-right" for="code"> Metode Pembayaran: </label>

                                            <div class="col-sm-9">
                                                <label for="inputWarning" id="lbMetodeBayar" class="col-xs-10"></label>

                                            </div>
                                        </div>

                                    </div>
                                </div>
                            </div>
                            </form>
                            <hr />
                            <div class="row-fluid wizard-actions">
                                <button class="btn btn-prev">
                                    <i class="icon-arrow-left"></i>
                                    Prev
                                </button>

                                <button class="btn btn-success btn-next" data-last="Finish " id="btnFinish">
                                    Next
                                    <i class="icon-arrow-right icon-on-right"></i>
                                </button>
                            </div>
                    </div><!-- /widget-main -->
                </div>
            </div>
                <!-- PAGE CONTENT ENDS -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</div>

<script>
    var totalPoint = <?php echo ($this->balance == "") ? 0 : $this->balance;?>;
    
    function formatCurrency(num) {
        num = num.toString().replace(/\Rp|\,/g,'');
        if(isNaN(num))
        num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10)
        cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
        num.substring(num.length-(4*i+3));
        return (((sign)?'':'-') + num + '.' + cents);
    }

    function setTotalHarga(qty){
        
        var harga = $('#price').val();
        var total = harga*qty;
        var total2 = formatCurrency(total);

        $('#totalPriceShow').val(total2);
        $('#totalPrice').val(total);

        if (totalPoint < total || eval(totalPoint) < 0){
            $('#rdTukarPoint').attr('disabled','disabled');
            $('#caraBayar').val("");
        }
        else{
            $('#rdTukarPoint').removeAttr('disabled');
        }
        
        
    }

    setTotalHarga($('#qty').val());

    function pilihBayar(val){
        $('#caraBayar').val(val);

        if (val == 3){

            document.getElementById("divBank").style.visibility = "visible";
            document.getElementById("divBank").style.position = "";
            
        }else{

            document.getElementById("divBank").style.visibility = "hidden";
            document.getElementById("divBank").style.position = "absolute";
        }
    }

    function konfirmasiPembelian(){
        
        var qty = $('#qty').val();
        var metodeBayar = $('#caraBayar').val();
        var totalPrice = $('#totalPrice').val();

        if (metodeBayar == ""){

            bootbox.dialog({
                    message: "<span class='bigger-110'>Pilih Metode Pembayaran</span>",
                    buttons:
                    {
                            "button" :
                             {
                                    "label" : "<i class='icon-ok'></i> Ok",
                                    "className" : "btn-sm btn-primary",
                                    //"callback": function() {
                                            //Example.show("great success");
                                    //}
                            }
                    }
            });
            return false;
        }
        
        var bayar = "";
        if (metodeBayar == 1) bayar = "Cash";
        else if (metodeBayar == 2) bayar = "Tukar Point (Point Anda: <?php echo number_format($this->balance);?>)";
        else{
            bayar = document.getElementById("divBank").innerHTML;
        }

        document.getElementById("lbKonfirmJumlah").innerHTML = qty;
        document.getElementById("lbMetodeBayar").innerHTML = bayar;
        document.getElementById("lbKonfirmTotal").innerHTML = formatCurrency(totalPrice);

        
        return true;

    }


</script>

<?php } ?>